﻿<?php
	session_start();
	if($_SESSION['uid']==""||$_SESSION['level']!=4){
		header("Location: ./exit.php");
		exit();
	}
	include('/php/tool/submitValidate.php');
	include('/php/tool/pdo.php');
	include('/php/bll/AdminRoleBLL.php');
	include('/php/class/admin-role.class.php');

	$role = isset($_GET['role']) ? $_GET['role'] : 0;
	$page = isset($_GET['page']) ? $_GET['page'] : 0;
	$pageSize = isset($_GET['pageSize']) ? $_GET['pageSize'] : 20;
	$search = isset($_GET['search']) ? $_GET['search'] : '';

	//输入验证
	$validate=new Validate();
	if(!$validate->regular('number',$role)){
		$role=0;
	}
	if(!$validate->regular('number',$page)){
		$page=0;
	}
	if(!$validate->regular('number',$pageSize)){
		$pageSize=0;
	}

	$adminRoleBLL=new AdminRoleBLL();
	//角色列表
	$roleList=$adminRoleBLL->getRoleList();
	//用户列表
	$userList=$adminRoleBLL->getUserList($role,$page,$pageSize,$search);

	//部门列表
	$departmentCount=0;
	$departmentString='';
	$departmentList=$adminRoleBLL->getDepartmentList();
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<script src="./scripts/crypto-js/core.js"></script>
<script src="./scripts/crypto-js/md5.js"></script>
<title>用户管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 
	<span class="c-gray en">&gt;</span> 角色管理 
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
		<i class="Hui-iconfont">&#xe68f;</i>
	</a>
</nav>
<div class="page-container">
	<div class="cl pd-5 mybg-2 bk-gray"> 
		<span class="l"> 
			<a href="javascript:;" onclick="admin_role_delete()" class="btn btn-danger radius">
				<i class="Hui-iconfont">&#xe6e2;</i> 批量删除
			</a> 
			<a class="btn btn-primary radius" href="javascript:;"  onclick="admin_user_modal()">
				<i class="Hui-iconfont">&#xe600;</i> 添加用户
			</a> 
		</span> 
		<span class="r">
			<button onclick="removeIframe()" class="btn btn-primary radius">关闭选项卡</button>
		</span>
	</div>
	<div class="mt-10">
		<form action="admin-role.php" method="get" class="form-horizontal mybg-2 bk-gray pt-5 pb-5">
			<div class="row cl mb-5">
				<label class="form-label col-xs-1" style="width:80px;margin:0;padding:0;line-height:31px;">角色名：</label>
				<div class="formControls col-xs-8 col-sm-2">
					<select id="role_select" name="role" class="select" size="1" style="height:31px">
					<option value="0">所有</option>
						<?php
							foreach($roleList as $myRole){
								if($role==$myRole['level']){
									echo '<option value="'.$myRole['level'].'" selected="">'.$myRole['name'].'</option>';
								}else{
									echo '<option value="'.$myRole['level'].'">'.$myRole['name'].'</option>';
								}
								
							}
							//$str='<option value="2">2</option>';
						?>
					</select>
				</div>
				<label class="form-label col-xs-4" style="width:120px;margin:0;padding:0;line-height:31px;">姓名或账号：</label>
				<div class="formControls col-xs-8 col-sm-2">
					<input  id="search" name="search" type="text" class="input-text" style="width:100%"  value="<?php echo $search;?>" placeholder="">
					<label id="search-error" class="error valid" for="search" style="display:none;">输入不符合要求</label>
				</div>
				<button id="btn-search" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 查找</button>
			</div>
		</form>
	</div>
	<table class="table table-border table-bordered table-hover table-bg mt-10">
		<thead>
			<tr>
				<th scope="col" colspan="8">用户管理</th>
			</tr>
			<tr class="text-c">
				<th width="25"><input type="checkbox" value="" name=""></th>
				<th width="120">账号</th>
				<th width="120">角色名</th>
				<th width="120">姓名</th>
				<th width="120">手机号</th>
				<th while="120">所属</th>
				<th width="350">描述</th>
				<th width="50">操作</th>
			</tr>
		</thead>
		<tbody>
			<?php
				foreach($userList as $user){
					$departmentName=$adminRoleBLL->getUserDepartment($user['uid']);
					echo '<tr class="text-c">
					<td><input type="checkbox" value="'.$user['uid'].'" name="users_checkbox"></td>
					<td class="uid">'.$user['uid'].'</td>
					<td class="role">'.$user['role'].'</td>
					<td class="name">'.$user['name'].'</td>
					<td class="phone">'.$user['phone'].'</td>
					<td class="department">'.$departmentName.'</td>
					<td class="describe">'.$user['describe'].'</td>
					<td class="f-14"><a title="编辑" href="javascript:;" onclick="admin_role_edit(this,'.$user['uid'].')" style="text-decoration:none">
					<i class="Hui-iconfont">&#xe6df;</i></a>
					<a title="删除" href="javascript:;" onclick="admin_role_del(this,'.$user['uid'].')" class="ml-5" style="text-decoration:none">
					<i class="Hui-iconfont">&#xe6e2;</i></a></td>
					</tr>';
				}
			?>
			<!--<tr class="text-c">
				<td><input type="checkbox" value="" name=""></td>
				<td>1</td>
				<td>超级管理员</td>
				<td></td>
				<td>1</td>
				<td>拥有至高无上的权利</td>
				<td class="f-14"><a title="编辑" href="javascript:;" onclick="admin_role_edit('角色编辑','admin-role-add.html','1')" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> <a title="删除" href="javascript:;" onclick="admin_role_del(this,'1')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
			</tr>-->
		</tbody>
	</table>
	<div class="modal-footer">
		<a class="btn" href="<?php echo './admin-role.php?role='.$role.'&page='.($page-1>0?$page-1:0).'&pageSize='.$pageSize.'&search='.$search; ?>">上一页</a>
			<span><select  id="dormitory_page" name="page" class="btn">
				<?php
					$option='<option value="0">1</option>';
					$pageMax=$adminRoleBLL->getUserListPage($role,$pageSize,$search);
					for($i=1;$i<$pageMax;$i++){
						if($i==$page){//selected=""
							$option=$option.'<option value="'.$i.'" selected="">'.($i+1).'</option>';
						}else{
							$option=$option.'<option value="'.$i.'" ">'.($i+1).'</option>';
						}
					}
					echo $option;
				?>
				<!--<option value="0" selected="">1</option>
				<option value="1">2</option>
				<option value="2">3</option>-->
			</select>
		</span>
		<a class="btn" href="<?php echo './admin-role.php?role='.$role.'&page='.($page+1<$pageMax?$page+1:$page).'&pageSize='.$pageSize.'&search='.$search; ?>">下一页</a>
	</div>
</div>

<!--遮罩层,添加用户-->
	<div id="modal-demo" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog" style="width:80%;">
			<div class="modal-content radius">
				<div class="modal-header">
					<h3 class="modal-title">添加用户</h3>
					<a class="close" data-dismiss="modal" aria-hidden="true" href="javascript:void();">×</a>
				</div>
				<div class="modal-body">
					<div class="mt-10">
						<div class="form-horizontal mybg-2 bk-gray pt-5 pb-5" id="form-article-add">
							<div class="row cl mb-5">
								<label class="form-label col-xs-4 col-sm-2">角色名：</label>
								<div class="formControls col-xs-8 col-sm-3">
									<select id="modal_select_role" name="modal_select_role" class="select" size="1" style="height:31px;">
										<?php
											foreach($roleList as $role){
												echo '<option value="'.$role['level'].'">'.$role['name'].'</option>';
											}
										?>
									</select>
								</div>
							</div>
							<div class="row cl mb-5">
								<label class="form-label col-xs-4 col-sm-2">账号：</label>
								<div class="formControls col-xs-8 col-sm-3">
									<input  id="modal_uid" type="text" class="input-text" style="width:100%" value="" placeholder="">
									<label id="modal_uid-error" class="error valid" for="modal_uid" style="display:none;">输入不符合要求</label>
								</div>
								<label class="form-label col-xs-4 col-sm-2">密码：</label>
								<div class="formControls col-xs-8 col-sm-3">
									<input  id="modal_password" type="password" class="input-text" style="width:100%" value="" placeholder="">
									<label id="modal_password-error" class="error valid" for="modal_password" style="display:none;">输入不符合要求</label>
								</div>
							</div>
							<div class="row cl mb-5">
								<label class="form-label col-xs-4 col-sm-2">姓名：</label>
								<div class="formControls col-xs-8 col-sm-3">
									<input  id="modal_name" name="modal_name" type="text" class="input-text" style="width:100%" value="" placeholder="">
									<label id="modal_name-error" class="error valid" for="modal_name" style="display:none;">输入不符合要求</label>
								</div>
								<label class="form-label col-xs-4 col-sm-2">手机号：</label>
								<div class="formControls col-xs-8 col-sm-3">
									<input  id="modal_phone" type="text" class="input-text" style="width:100%" value="" placeholder="">
									<label id="modal_phone-error" class="error valid" for="modal_phone" style="display:none;">输入不符合要求</label>
								</div>
							</div>
							<div class="row cl">
								<label class="form-label col-xs-4 col-sm-2">所属：</label>
								<div class="formControls col-xs-8 col-sm-9">
									<table class="table table-border table-bordered table-bg">
										<thead>
											<tr class="text-c">
												<th>选择</th>
												<th>所属</th>
												<th>选择</th>
												<th>所属</th>
												<th>选择</th>
												<th>所属</th>
												<th>选择</th>
												<th>所属</th>
											</tr>
										</thead>
										<tbody id="department-table">
											<?php
												//echo json_encode($departmentList,JSON_UNESCAPED_UNICODE);
												foreach($departmentList as $department){
													$departmentString=$departmentString.'<td><input name="department" type="checkbox" value="'.$department['department_id'].'"/></td>';
													$departmentString=$departmentString.'<td>'.$department['department_name'].'</td>';
													$departmentCount++;
													if($departmentCount%4==0){
														echo '<tr class="text-c">';
														echo $departmentString;
														echo '</tr>';

														$departmentString='';
													}
												}

												if($departmentCount%4!=0){
													for($i=$departmentCount%4;$i<4;$i++){
														$departmentString=$departmentString.'<td></td><td></td>';
													}
													echo '<tr class="text-c">';
													echo $departmentString;
													echo '</tr>';
												}
											?>
										</tbody>
									</table>
								</div>
							</div>
						</div>
						<div class="modal-footer mybg-2">
							<button id="add-user" class="btn btn-primary radius">确定</button>
							<button class="btn btn-default radius" data-dismiss="modal" aria-hidden="true">取消</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
<!--遮罩层,编辑用户信息-->
	<div id="modal-update" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog" style="width:80%;">
			<div class="modal-content radius">
				<div class="modal-header">
					<h3 class="modal-title">编辑用户信息</h3>
					<a class="close" data-dismiss="modal" aria-hidden="true" href="javascript:void();">×</a>
				</div>
				<div class="modal-body">
					<div class="mt-10">
						<div class="form-horizontal mybg-2 bk-gray pt-5 pb-5" id="form-article-add">
							<div class="row cl mb-5">
								<label class="form-label col-xs-4 col-sm-2">角色名：</label>
								<div class="formControls col-xs-8 col-sm-3">
									<select id="update_select_role" name="update_select_role" class="select" size="1" style="height:31px;">
										<?php
											foreach($roleList as $role){
												echo '<option value="'.$role['level'].'">'.$role['name'].'</option>';
											}
										?>
									</select>
								</div>
							</div>
							<div class="row cl mb-5">
								<label class="form-label col-xs-4 col-sm-2">账号：</label>
								<div class="formControls col-xs-8 col-sm-3">
									<input  id="update_uid" type="text" class="input-text" disabled="disabled" style="width:100%" value="" placeholder="">
									<label id="update_uid-error" class="error valid" for="update_uid" style="display:none;">输入不符合要求</label>
								</div>
								<label class="form-label col-xs-4 col-sm-2">密码：</label>
								<div class="formControls col-xs-8 col-sm-3">
									<input  id="update_password" type="password" class="input-text" disabled="disabled" style="width:100%" value="" placeholder="">
									<label id="update_password-error" class="error valid" for="update_password" style="display:none;">输入不符合要求</label>
								</div>
							</div>
							<div class="row cl mb-5">
								<label class="form-label col-xs-4 col-sm-2">姓名：</label>
								<div class="formControls col-xs-8 col-sm-3">
									<input  id="update_name" name="update_name" type="text" class="input-text" style="width:100%" value="" placeholder="">
									<label id="update_name-error" class="error valid" for="update_name" style="display:none;">输入不符合要求</label>
								</div>
								<label class="form-label col-xs-4 col-sm-2">手机号：</label>
								<div class="formControls col-xs-8 col-sm-3">
									<input  id="update_phone" type="text" class="input-text" style="width:100%" value="" placeholder="">
									<label id="update_phone-error" class="error valid" for="update_phone" style="display:none;">输入不符合要求</label>
								</div>
							</div>
							<div class="row cl">
								<label class="form-label col-xs-4 col-sm-2">所属：</label>
								<div class="formControls col-xs-8 col-sm-9">
									<table class="table table-border table-bordered table-bg">
										<thead>
											<tr class="text-c">
												<th>选择</th>
												<th>所属</th>
												<th>选择</th>
												<th>所属</th>
												<th>选择</th>
												<th>所属</th>
												<th>选择</th>
												<th>所属</th>
											</tr>
										</thead>
										<tbody id="update-department-table">
											<?php
												$departmentCount=0;
												$departmentString='';
												//echo json_encode($departmentList,JSON_UNESCAPED_UNICODE);
												foreach($departmentList as $department){
													$departmentString=$departmentString.'<td><input name="update_department" type="checkbox" value="'.$department['department_id'].'"/></td>';
													$departmentString=$departmentString.'<td>'.$department['department_name'].'</td>';
													$departmentCount++;
													if($departmentCount%4==0){
														echo '<tr class="text-c">';
														echo $departmentString;
														echo '</tr>';

														$departmentString='';
													}
												}

												if($departmentCount%4!=0){
													for($i=$departmentCount%4;$i<4;$i++){
														$departmentString=$departmentString.'<td></td><td></td>';
													}
													echo '<tr class="text-c">';
													echo $departmentString;
													echo '</tr>';
												}
											?>
										</tbody>
									</table>
								</div>
							</div>
						</div>
						<div class="modal-footer mybg-2">
							<button id="update-user" class="btn btn-primary radius">确定</button>
							<button class="btn btn-default radius" data-dismiss="modal" aria-hidden="true">取消</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="scripts/admin-role.jquery.js"></script>
</body>
</html>